import 'package:flutter/material.dart';
import 'package:flutter_chat/common/style/styles.dart';

class CustomInput extends StatelessWidget {
  /// 控制器
  final TextEditingController? controller;

  /// 背景颜色
  final Color bgColor;

  /// 显示边框
  final bool showBorder;

  /// 最小行数
  final int minLines;

  /// 最大行数
  final int maxLines;

  /// 发生改变时执行
  final Function(String)? onChanged;

  /// 是否隐藏文本
  final bool obscureText;

  /// 提示文字
  final String? hintText;
  const CustomInput({
    super.key,
    this.showBorder = false,
    this.bgColor = Colors.white,
    this.minLines = 1,
    this.maxLines = 1,
    this.controller,
    this.onChanged,
    this.hintText,
    this.obscureText = false,
  });

  @override
  Widget build(BuildContext context) {
    return TextField(
      controller: controller,
      autofocus: false,
      keyboardType: TextInputType.multiline,
      minLines: minLines,
      maxLines: maxLines,
      onChanged: onChanged,
      obscureText: obscureText,
      decoration: InputDecoration(
        fillColor: bgColor,
        filled: true,
        hintText: hintText,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(
            AppTheme.radius,
          ),
          borderSide: showBorder ? const BorderSide() : BorderSide.none,
        ),
        isDense: true,
        contentPadding: const EdgeInsets.all(10),
      ),
    );
  }
}
